# 2097151 # flag{110111100101001101001} for num in range(2097151): s = bin(num)[2:] while len(s) < 21: s = '0' + s print(s) flag = 'flag{' + s + "}" assert flag.startswith("flag{") assert flag.endswith("}") assert len(flag) == 27 deflfsr(R, mask): output = (R << 1) & 0xffffff i = (R & mask) & 0xffffff lastbit = 0 while i != 0: lastbit ^= (i & 1) i = i >> 1 output ^= lastbit return (output, lastbit) R = int(flag[5:-1], 2) mask = 0x100002 f = open("key", "ab") for i in range(12): tmp = 0 for j in range(8): (R, out) = lfsr(R, mask) tmp = (tmp << 1) ^ out f.write(chr(tmp)) f.close()
# 2097151 for temp in range(1200000,2097151): s = bin(temp)[2:] while len(s) < 21: s = '0' + s flag = 'flag{' + s + "}" assert flag.startswith("flag{") assert flag.endswith("}") assert len(flag) == 27 def nlfsr(R, mask): output = (R << 1) & 0xffffff i = (R & mask) & 0xffffff lastbit = 0 changesign = True while i != 0: if changesign: lastbit &= (i & 1) changesign = False else: lastbit ^= (i & 1) i = i >> 1 output ^= lastbit return (output, lastbit) R = int(flag[5:-1], 2) mask = 0b110110011011001101110 a = '' for i in range(10): tmp = 0 for j in range(8): (R, out) = nlfsr(R, mask) tmp = (tmp << 1) ^ out a += chr(tmp) if a in fs[:15]: print(flag)